package com.act.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.act.domain.AttendanceManagement;
import com.act.domain.CustomsManagement;
import com.act.dto.Response;
import com.act.service.api.ICustomsManagementService;

@RestController
@RequestMapping("cm")
public class CustomesManagementController {
	
	@Resource
	private  ICustomsManagementService customsManagementService;
	
    @RequestMapping(value="/get/{type}/{payee}",method=RequestMethod.GET)
    public @ResponseBody List<CustomsManagement> getAllByTypeOrPayyee(@PathVariable String type,@PathVariable String payee){
    	List<CustomsManagement> list=customsManagementService.getAllByTypeOrPayyee(type, payee);
        return list;
    }
    
//    @RequestMapping(value="/get",method = RequestMethod.GET)
//    public ModelAndView getAllList() {
////		List<CustomsManagement> amlist=customsManagementService.getAll();
//		ModelAndView maView=new ModelAndView();
//		maView.setViewName("user/register");
////		maView.addObject("cmlist",amlist);
////	
//      return maView;
//    }
    
//    @RequestMapping(value = "/add",method = RequestMethod.POST)
//    public ModelAndView add(CustomsManagement customsManagement) {
//    	customsManagementService.add(customsManagement);
//		ModelAndView maView=new ModelAndView();
//		maView.setViewName("user/register");
//		maView.addObject("cm",customsManagement);
//	
//      return maView;
//    }
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(CustomsManagement customsManagement) {
    	 try {
    		 customsManagementService.add(customsManagement);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
	
    }
    
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Response add(int id) {
    	 try {
    		 customsManagementService.delete(id);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
	
    }
    
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Response update(CustomsManagement customsManagement) {
    	 try {
    		 customsManagementService.update(customsManagement);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
	
    }
}
